import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import {
  Router,
  Route,
  IndexRoute,
  Redirect,
  browserHistory,
} from 'react-router';
import { AppContainer } from 'react-hot-loader';
import configureStore from './stores';

import RootComponent from './modules/root';
import HomeComponent from './modules/home';

const [store, storeHistory] = configureStore(browserHistory);

const bootstrap = () => {
  ReactDOM.render(
    <AppContainer>
      <Provider store={store}>
        <Router onUpdate={() => window.scrollTo(0, 0)} history={storeHistory}>
          <Route path="/" component={RootComponent}>
            <IndexRoute component={HomeComponent} />
            <Redirect from="*" to="/" />
          </Route>
        </Router>
      </Provider>
    </AppContainer>,
    document.getElementById('root'),
  );
};

export default bootstrap;
